home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / ikFkBlendValue.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.3 KB  |  151 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. global proc float ikFkBlendValue(string $selectionList[])
  18. //
  19. //    Description:
  20. //        Returns the float value of the solver blend value of the
  21. //        selected joint chains or ikHandles. If all the selected objects
  22. //      do not have the same blend value, returns -1.    
  23. //
  24. {
  25.     float $blendValue = -1.0;
  26.  
  27.     int $nOtherHandles = 0;
  28.     string $otherHandles[];
  29.     int $nOtherJoints = 0;
  30.     string $otherJoints[];
  31.  
  32.     string $xforms[] = `ls -type transform $selectionList`;
  33.     int $nXforms = size($xforms);
  34.     if (0 == $nXforms) {
  35.         return $blendValue;
  36.     }
  37.  
  38.     string $ikRelated[] = `ls -type joint -type ikHandle $selectionList`;
  39.     int $nIKRelated = size($ikRelated);
  40.     if ($nIKRelated != $nXforms) {
  41.         string $item;
  42.         for ($item in $xforms) {
  43.             string $attrName;
  44.             if (size(`ls ($item+".solverEnable")`)) {
  45.                 $attrName = ($item+".solverEnable");
  46.             } else if (size(`ls ($item+".ikBlend")`)) {
  47.                 $attrName = ($item+".ikBlend");
  48.             }
  49.             if (size($attrName)) {
  50.                 string $cnx[] = `listConnections -d 0 $attrName`;
  51.  
  52.                 if (size($cnx) > 0 &&
  53.                     !size(`ls -type joint $cnx[0]`)) {
  54.                     if (size(`ls -type ikHandle $cnx[0]`) > 0) {
  55.                         $otherHandles[$nOtherHandles++] = $cnx[0];
  56.                     } else if (size(`ls -type joint $cnx[0]`) > 0) {
  57.                         $otherJoints[$nOtherHandles++] = $cnx[0];
  58.                     }
  59.                 }
  60.             }
  61.         }
  62.     }
  63.  
  64.     if ($nIKRelated == 0 && $nOtherHandles == 0 && $nOtherJoints == 0) {
  65.         return $blendValue;
  66.     }
  67.  
  68.     int $hasResult = false;
  69.     int $mixed = false;
  70.  
  71.     string $selectedHandles[] = `ls -type "ikHandle" $ikRelated`;
  72.     int $nHandles = size($selectedHandles);
  73.  
  74.     //    Add the other handles that may be involved.
  75.     //
  76.     for ($item in $otherHandles) {
  77.         $selectedHandles[$nHandles++] = $item;
  78.     }
  79.  
  80.     string $item;
  81.     for ($item in $selectedHandles) {
  82.         float $currBlend = `getAttr ($item+".ikBlend")`;
  83.         
  84.         if (!$hasResult) {
  85.             $blendValue = $currBlend;
  86.             $hasResult = true;
  87.         } else {
  88.             if (abs($blendValue - $currBlend) > 0.001) {
  89.                 $mixed = true;
  90.                 break;
  91.             } 
  92.         }
  93.     }
  94.  
  95.     if (!$mixed) {
  96.         //  Only look at the joints if it is necessary.
  97.         //
  98.         string $handles[] = `ls -type ikHandle`;
  99.         string $jointList[] = `ls -type "joint" $ikRelated`;
  100.         int $jointIndex = size($jointList);
  101.         for ($item in $otherJoints) {
  102.             $jointList[$jointIndex++] = $item;
  103.         }
  104.  
  105.         string $selected;
  106.         for ($selected in $jointList) {
  107.             string $h;
  108.             for ($h in $handles) {
  109.                 string $joints[] = `ikHandle -q -jl $h`;
  110.  
  111.                 int $nJoints = size($joints);
  112.                 $joints[$nJoints] = `ikHandle -q -sj $h`;
  113.  
  114.                 string $j;
  115.                 for ($j in $joints) {
  116.                     if (size(`match $selected $j`) > 0 &&
  117.                         size(`match ($selected+"|") $j`) == 0) {
  118.                         string $attrName = ($h+".ikBlend");
  119.                         if (size(`ls ($h+".solverEnable")`)) {
  120.                             $attrName = ($h+".solverEnable");
  121.                         }
  122.                         float $currBlend = `getAttr $attrName`;
  123.                         if (!$hasResult) {
  124.                             $blendValue = $currBlend;
  125.                             $hasResult = true;
  126.                         } else {
  127.                             if (abs($blendValue - $currBlend) > 0.001) {
  128.                                 $mixed = true;
  129.                                 break;
  130.                             }
  131.                         }
  132.                     }
  133.                 }
  134.  
  135.                 if ($mixed) {
  136.                     break;
  137.                 }
  138.             }
  139.             if ($mixed) {
  140.                 break;
  141.             }
  142.         }
  143.     }
  144.  
  145.     if ($mixed) {
  146.         $blendValue = -1.0;
  147.     }
  148.  
  149.     return $blendValue;
  150. }
  151.